#include<iostream>
#define MAXN 10

int hoare_partition(int arr[],int p,int q){
    int i,j,x,t;
    x=arr[p];
    i=p;
    j=q;
    while(1){
		for(;i<q && arr[i] < x;i++);
		for(;j>p && arr[j]>=x;j--);
        if(i<j){
            t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }else{
            return j;
		}
    }
}

void hoare_qsort(int arr[],int p,int q){
	//printf("%d %d\n",p,q);
    if(p>=q)
        return;
    int pivot =  hoare_partition(arr,p,q);
	hoare_qsort(arr,p,pivot);
    hoare_qsort(arr,pivot+1,q);
}

int partition(int arr[],int p,int q){
    int i,j,x,t;
    x = arr[q];
    i = p-1;
    for(j=p;j<=q;j++){
        if(arr[j]<x){
            t = arr[++i];
            arr[i] = arr[j];
            arr[j] = t;
        }
    }
    t = arr[i+1];
    arr[i+1] = arr[q];
    arr[q] = t;
    return i+1;
}

void quick_sort(int arr[],int p, int q){
    if(p>=q)
        return;
    int pivot = partition(arr,p,q);
    quick_sort(arr,p,pivot-1);
    quick_sort(arr,pivot,q);
}


int main(){
    int arr[MAXN] = {6,9,11,5,1,2,4,10,8,3};
    printf("Classical quick sort:");
    quick_sort(arr,0,MAXN-1);
    for(int i=0;i<MAXN;i++)
        printf("%d ",arr[i]);
    printf("\nEarliest quick sort:");
    hoare_qsort(arr,0,MAXN-1);
    for(int i=0;i<MAXN;i++)
        printf("%d ",arr[i]);
}
